<?php

setlocale(LC_ALL, 'ru_RU.UTF8');
set_include_path('../include');
//error_reporting(E_ALL);
require_once 'Zend/Loader/Autoloader.php';

$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);

// setup the application logger
$logger = new Zend_Log(new Zend_Log_Writer_Null());


try {
    $config = new Zend_Config_Ini('../settings.ini', 'development');
    Zend_Registry::set('config', $config);


    // alter the application logger
    $logger->addWriter(new Zend_Log_Writer_Stream($config->logging->file));

    Zend_Registry::set('logger', $logger);


    // connect to the database
    $params = array('host' => $config->database->hostname,
        'username' => $config->database->username,
        'password' => $config->database->password,
        'dbname' => $config->database->database);

    $db = Zend_Db::factory($config->database->type, $params);
    $db->getConnection();

    Zend_Registry::set('db', $db);


    // setup application authentication
    $auth = Zend_Auth::getInstance();
    $auth->setStorage(new Zend_Auth_Storage_Session());


    // handle the user request
    $controller = Zend_Controller_Front::getInstance();
    $controller->setControllerDirectory($config->paths->base .
            '/include/Controllers');
    //$controller->registerPlugin(new CustomControllerAclManager($auth));

    // setup the view renderer
    $vr = new Zend_Controller_Action_Helper_ViewRenderer();
    $vr->setView(new Templater());
    $vr->setViewSuffix('tpl');
    Zend_Controller_Action_HelperBroker::addHelper($vr);

    $controller->dispatch();
} catch (Exception $ex) {
    $logger->emerg($ex->getMessage());

    /*header('Location: /error.html');
    exit;*/
    
    echo $ex->getMessage();
}
?>